package com.sh.ndt.user.service;

import com.sh.ndt.common.entity.LoginParam;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;

import com.sh.ndt.exception.DAOException;
import com.sh.ndt.exception.ServiceException;
import com.sh.ndt.user.dao.UserDAO;
import com.sh.ndt.user.entity.User;

public class UserServiceImpl implements UserService {

    private static final Logger LOGGER = Logger.getLogger(UserServiceImpl.class);

    UserDAO userDao;

    public UserServiceImpl(UserDAO userDao) throws ServiceException {
        try {
            LOGGER.debug("*************** Inside UserServiceImpl Constructor ***************");
            this.userDao = userDao;

        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

    public List<User> addEditUser(User userDto) throws ServiceException {
        try {

            LOGGER.debug("... addEditUser(UserDTO userDto) ...");

            return userDao.addEditUser(userDto);

        } catch (DAOException e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public User validateUser(User userDto) throws ServiceException {
        try {
            return userDao.validateUser(userDto);
        } catch (DAOException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public List<User> selectUser() throws ServiceException {
        try {

            LOGGER.debug("... selectUser() ...");

            return userDao.selectUser();

        } catch (DAOException e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public User getUser(String userId, String primaryEmailId) throws ServiceException {
        // TODO Auto-generated method stub
        return null;
    }

//	@Override
//	public int addNewUserPlan(UserPlan userPlan) throws ServiceException {
//		// TODO Auto-generated method stub
//		try {
//			userDao.addNewUserPlan(userPlan);
//		} catch (DAOException e) {
//			e.printStackTrace();
//		}
//		return 0;
//	}
//
//	@Override
//	public int commitSelectedPlan(Hashtable plans) throws ServiceException {
//
//    	Enumeration<Integer> enumKey = plans.keys();
//    	
//    	while(enumKey.hasMoreElements()){
//    		Integer key = enumKey.nextElement();
//    		UserPlan userPlan = (UserPlan)plans.get(key);
//    		System.out.println("Plan Id "+userPlan.getPlanId());
//    		System.out.println("Sub Id "+userPlan.getSubjectId());
//    		System.out.println("Level Id "+userPlan.getLevelId());
//    		System.out.println("Test Type "+userPlan.getTestType());
//    		System.out.println("User Id "+userPlan.getUserId());
//    		System.out.println("++++++++++++++++++++++++++");
//    		
//    		addNewUserPlan(userPlan);
//    	}
//		
//		return 0;
//	}
//
//	@Override
//	public List<UserPlan> getUserPlan(int userId) throws ServiceException {
//
//		try {
//			return userDao.getUserPlan(userId);
//		} catch (DAOException e) {
//			e.printStackTrace();
//		}
//		return null;
//	}
    @Override
    public List<User> validateUser(LoginParam loginParam)  throws ServiceException{
        return userDao.validateUser(loginParam);
    }

}
